/**
 * 艺术作品（电影，音乐，句子，）排行
 */

const { Sequelize ,Model } = require("sequelize");
const { sequelize } = require('@core/db.js')
const { ArtNotExistException } = require("@core/http-exception.js");
const { Art } = require("@model/art.js");

class Flow extends Model {
  // 获取最新一期
  static async getLatestArt () {
    const flow = await Flow.findOne({
      order: [
        ['index', 'DESC']
      ]
    })
    if (!flow) {
      throw new ArtNotExistException('没有最新数据')
    }
    console.log('flow', flow);
    let art = await Art.getDetail(flow.artId, flow.type)
    await art.setDataValue('status', flow.status)
    await art.setDataValue('index', flow.index)
    return art
  }
}

Flow.init({
  artId: Sequelize.INTEGER,
  type: Sequelize.INTEGER,
  index: Sequelize.INTEGER,
  status: Sequelize.INTEGER
}, {
  sequelize,
  tableName: 'flow'
})

module.exports = {
  Flow
}